<template>
    <el-dialog :title="titleMap[mode]+' '+ form.id" v-model="visible" draggable :show-fullscreen="true" :width="900" destroy-on-close @closed="$emit('closed')">
        <el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="120px" label-position="left">
            <el-form-item label="拍卖名称" prop="title">
                <el-input v-model="form.title" clearable></el-input>
        	</el-form-item>
            <el-form-item label="店铺id" prop="store_id">
                <el-input-number v-model="form.store_id"></el-input-number>
        	</el-form-item>

            <el-form-item label="申请状态" prop="apply_status" >
                <el-radio :disabled="form.apply_status!=1" v-model="form.apply_status" v-for="(item,index) in apply_status_option" :key="index" :label="index">{{item}}</el-radio>
        	</el-form-item>

            <el-form-item label="拍卖类型" prop="type_status" >
                <el-radio :disabled="true" v-model="form.type_status" v-for="(item,index) in type_status_option" :key="index" :label="index">{{item}}</el-radio>
        	</el-form-item>
            <el-form-item label="开始类型" prop="start_status">
                <el-radio :disabled="true" v-model="form.start_status" v-for="(item,index) in start_status_option" :key="index" :label="index">{{item}}</el-radio>
        	</el-form-item>
            <el-form-item label="商品" prop="goods_id">
                <el-input-number :disabled="true" v-model="form.goods_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="商品规格" prop="goods_sku_price_ids">
                <el-input :disabled="true" v-model="form.goods_sku_price_ids" clearable></el-input>
        	</el-form-item>
            <el-form-item label="起拍价格" prop="start_price">
                <el-input-number :disabled="true" v-model="form.start_price"></el-input-number>
        	</el-form-item>
            <el-form-item label="最低价格(保留价)" prop="minimum_price">
                <el-input-number :disabled="true" v-model="form.minimum_price"></el-input-number>
        	</el-form-item>
            <el-form-item label="加价幅度" prop="plus_price">
                <el-input-number :disabled="true" v-model="form.plus_price"></el-input-number>
        	</el-form-item>
            <el-form-item label="买家保证金" prop="buyer_surety">
                <el-input-number :disabled="true" v-model="form.buyer_surety"></el-input-number>
        	</el-form-item>
            <el-form-item label="出局贝壳补贴" prop="out_perk_shell">
                <el-input-number :disabled="true" v-model="form.out_perk_shell"></el-input-number>
        	</el-form-item>
            <el-form-item label="报名出局贝壳补贴" prop="enroll_out_perk_shell">
                <el-input-number :disabled="true" v-model="form.enroll_out_perk_shell"></el-input-number>
        	</el-form-item>
            <el-form-item label="报名需要积分" v-if="form.type_status==3 || form.type_status==2" prop="enroll_score">
                <el-input-number :disabled="true" v-model="form.enroll_score"></el-input-number>
        	</el-form-item>
            <el-form-item label="入场积分" v-if="form.type_status==4 || form.type_status==5" prop="admission_score">
                <el-input-number :disabled="true" v-model="form.admission_score"></el-input-number>
        	</el-form-item>
            <el-form-item label="最高成交价"  prop="max_price">
                <el-input-number :disabled="true" v-model="form.max_price"></el-input-number>
        	</el-form-item>
            <el-form-item label="最低成交价" v-if="form.type_status==4 " prop="min_price">
                <el-input-number :disabled="true" v-model="form.min_price"></el-input-number>
        	</el-form-item>
            <el-form-item label="预展示多少s" prop="advance_show_s">
                <el-input-number :disabled="true" v-model="form.advance_show_s"></el-input-number>
        	</el-form-item>
            <el-form-item label="结束时长" prop="end_s">
                <el-input-number :disabled="true" v-model="form.end_s"></el-input-number>
        	</el-form-item>
            <el-form-item label="开始时间" prop="start_time">
                <el-date-picker :disabled="true" v-model="form.start_time" type="datetime"></el-date-picker>
        	</el-form-item>
            <el-form-item label="结束时间" prop="end_time">
                <el-date-picker :disabled="true" v-model="form.end_time" type="datetime"></el-date-picker>
        	</el-form-item>
            <el-form-item label="几个周期" prop="cycle">
                <el-input-number :disabled="true" v-model="form.cycle"></el-input-number>
        	</el-form-item>
            <el-form-item label="发货模板" prop="dispatch_ids">
                <el-input :disabled="true" v-model="form.dispatch_ids" clearable></el-input>
        	</el-form-item>

            <el-form-item label="自动状态" prop="auto_status">
                <el-radio :disabled="true" v-model="form.auto_status" v-for="(item,index) in auto_status_option" :key="index" :label="index">{{item}}</el-radio>
        	</el-form-item>
            <el-form-item label="状态" prop="status">
                <el-radio :disabled="true" v-model="form.status" v-for="(item,index) in status_option" :key="index" :label="index">{{item}}</el-radio>
        	</el-form-item>
            <el-form-item label="第几个周期" prop="how_cycle">
                <el-input-number :disabled="true" v-model="form.how_cycle"></el-input-number>
        	</el-form-item>
            <el-form-item label="预展示id" prop="auction_advance_show_id">
                <el-input-number :disabled="true" v-model="form.auction_advance_show_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="结束时间id" prop="auction_end_id">
                <el-input-number :disabled="true" v-model="form.auction_end_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="改价费" prop="change_price">
                <el-input-number :disabled="true" v-model="form.change_price"></el-input-number>
        	</el-form-item>
        </el-form>
        <template #footer>
            <el-button @click="visible=false" >取 消</el-button>
            <el-button v-if="mode!='read'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
        </template>
    </el-dialog>
</template>

<script>
    
    export default {
        emits: ['success', 'closed'],
        
        data() {
            return {
                mode: "create",
                titleMap: {
                    read: '查看',
                    create: '新增',
                    update: '编辑',
                },
                visible: false,
                isSaveing: false,
                form: {
                    id: 0,
					title: '',
					store_id: '',
					type_status: '',
					start_status: '',
					goods_id: '',
					goods_sku_price_ids: '',
					start_price: '',
					minimum_price: '',
					plus_price: '',
					buyer_surety: '',
					out_perk_shell: '',
					enroll_out_perk_shell: '',
					enroll_score: '',
					admission_score: '',
					max_price: '',
					min_price: '',
					advance_show_s: '',
					end_s: '',
					start_time: '',
					end_time: '',
					cycle: '',
					dispatch_ids: '',
					apply_status: '',
					auto_status: '',
					status: '',
					how_cycle: '',
					auction_advance_show_id: '',
					auction_end_id: '',
					change_price: '',
                },
                rules: {
                },
				type_status_option:{"1":"贝壳竞拍","2":"降价拍","3":"升价拍","4":"暗拍(降价拍)","5":"暗拍(升价拍)"},
				start_status_option:{"time":"时间","number":"人数"},
				apply_status_option:{"1":"待审核","2":"通过","3":"拒绝"},
				auto_status_option:{"1":"非自动","2":"自动"},
				status_option:{"1":"待展示","2":"预展示","3":"进行中","5":"结束","6":"已下架"},
            }
        },
        created() {
            // this.$TABLE.setFilterValue(this);
            this.getdataList();
        },
        methods: {

            async getdataList(){
                var res = await this.$API.store.read.get({page: 1,pageSize: 999999})
                var list = res.data.list;
                var cate = [];
                for (let index = 0; index < list.length; index++) {
                    cate[list[index].id] = list[index].id+'👉'+list[index].name;                    
                }
                console.log(cate);
                this.dataList = cate;
            },
            open(mode='create'){
                this.mode = mode;
                this.visible = true;
                return this
            },
            submit(){
                this.$refs.dialogForm.validate(async (valid) => {
                    if (valid) {
                        this.isSaveing = true;
                        var res = await this.$API.auction[this.mode].post(this.form);
                        this.isSaveing = false;
                        if(res.code == 200){
                            this.$emit('success', this.form, this.mode)
                            this.visible = false;
                            this.$message.success(res.message)
                        }else{
                            this.$alert(res.message, "提示", {type: 'error'})
                        }
                    }else{
                        return false;
                    }
                })
            },
            setData(data){
                this.$TABLE.assign(this,data);
            }
        }
    }
</script>